<?
Class KUMail{
    function CheckEmailValidate($email){
        // include SMTP Email Validation Class

        require_once('smtp_validateEmail.class.php');

        // the email to validate
        //$email = 'khuongxuantruong@zing.vn';
        // an optional sender
        $sender = 'postmaster@localhost';
        // instantiate the class
        $SMTP_Validator = new SMTP_validateEmail();
        // turn on debugging if you want to view the SMTP transaction
        $SMTP_Validator->debug = false;
        // do the validation
        $results = $SMTP_Validator->validate(array($email), $sender);
        // view results
        return isset($results[$email])?$results[$email]:false;
        echo $email.' is '.($results[$email] ? 'valid' : 'invalid')."\n";
//        
//        // send email? 
//        if ($results[$email]) {
//            mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email
//        } else {
//            echo 'The email addresses you entered is not valid';
//        }
    }
    function Test(){
        require_once 'PHPMailer_5.2.2/class.phpmailer.php';
        $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

        try {
            $mail->AddAddress('khuongxuantruong@zing.vn', 'John Doe');
            $mail->SetFrom('khuongxuantruong@gmail.com', 'First Last');
            //$mail->AddReplyTo('name@yourdomain.com', 'First Last');
            $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
            $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
            //$mail->MsgHTML(file_get_contents('contents.html'));
            $mail->MsgHTML('adasdasd');
            //$mail->AddAttachment('images/phpmailer.gif');      // attachment
            //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
            $mail->Send();
            echo "Message Sent OK</p>\n";
        } catch (phpmailerException $e) {
            echo "phpmailerException:".$e->errorMessage(); //Pretty error messages from PHPMailer
        } catch (Exception $e) {
            echo "Error:".$e->getMessage(); //Boring error messages from anything else!
        }
    }
    function test2($title,$body,$toemail){
        $guser='khuongxuantruong@gmail.com';
        $gpass="shaphia1900";
        $gname='K.U';
        KUMail::smtpmailerGmail($toemail,$title,$body,$guser,$gpass,$gname);
    }
    public static function  smtpmailerGmail($SenderEmail,$text,$body,$guser,$gpass,$gname) {
        require_once 'PHPMailer_5.2.2/class.phpmailer.php';
        require_once 'PHPMailer_5.2.2/class.smtp.php';
        ////mail nguoi nhan , tai khoan (ten nguoi nhan) , pass muon gui , tieu de mail , noi dung mail , account gmail, pass gmail , ten nguoi gui
        $mail = new PHPMailer();
        $mail->IsSMTP(); // set mailer to use SMTP
        $mail->Host = "smtp.gmail.com"; // specify main and backup server
        $mail->Port = 465; // set the port to use
        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->SMTPSecure = 'ssl';
        $mail->Mailer = "smtp";
        $mail->CharSet="utf-8";
        $mail->Username = $guser; // your SMTP username or your gmail username
        $mail->Password = $gpass; // your SMTP password or your gmail password
        $from = $guser; // Reply to this email
        $mail->AddReplyTo($guser, "Trả Lời");
        $mail->From = $from;
        $mail->FromName = $gname; // Name to indicate where the email came from when the recepient received
        foreach ($SenderEmail as $se){
            $mail->AddAddress($se["email"],$se["name"]);
        }

        $mail->AddReplyTo($from,$gname);
        $mail->WordWrap = 50; // set word wrap
        $mail->IsHTML(true); // send as HTML
        $mail->Subject = $text;
        $mail->Body = $body; //HTML Body
        $mail->AltBody = "Thông Báo Xác Nhận Phiếu Mượn Thiết Bị"; //Text Body
        $mail->SMTPDebug = 1;
        if(!$mail->Send())
        {
             echo "<h1>Loi khi goi mail: " . $mail->ErrorInfo . '</h1>';
             
        }else{
            
        }
    }
    
}
?>